package itheima.lianxi1;
/*
        定义一个长度为5的数组，随机生成5个（0-100）的值存入数组。
        从小到大或者从大到小进行排序。
        例如：（排列前）【3,5,2,7,1】
              （排列后）【1,2,3,5,7】
 */

import java.util.Random;

public class Lianxi {

    public static void main(String[] args) {
        int[] arr = new int[5];
        String str = "[";
        String str2 = "[";

        Random r = new Random();
        for (int i = 0; i < arr.length; i++) {
            arr[i] = r.nextInt(101);
            if (i == arr.length - 1){
                str = str + arr[i] + "]";
            }else {
                str = str + arr[i] + ",";
            }
        }
        System.out.println("排列前数组为:" + str);

        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = i + 1; j < arr.length; j++) {
                if (arr[i] > arr[j]){
                    int temp = arr[j];
                    arr[j] = arr[i];
                    arr[i] = temp;
                }
            }
        }
        for (int i = 0; i < arr.length; i++) {
            if (i == arr.length - 1){
                str2 = str2 + arr[i] + "]";
            }else {
                str2 = str2 + arr[i] + ",";
            }
        }
        System.out.println("排列后数组为:" + str2);
    }
}
